package com.woniuxy.controller;

import com.woniuxy.config.MqConfig;
import com.woniuxy.entity.Food;

import com.woniuxy.entity.foodinfo;
import com.woniuxy.service.FoodService;
import com.woniuxy.utils.ResponseResult;
import com.woniuxy.vo.UserFoodOrderDetailVo;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/catering")
public class FoodController {
    @Autowired
    private FoodService foodService;
    @Autowired
    private RabbitTemplate rabbitTemplate;


    @GetMapping("/findAll")  //
    public ResponseResult<List<Food>> findAll(){
        List<Food> foodList = foodService.findAll();
        return ResponseResult.success(foodList);
    }

    //新增餐品订单
    @PostMapping("/addfoodOrder")
    public ResponseResult<String> addfoodOrder(@RequestBody foodinfo fi){
        foodService.addfoodOrder(fi);


        return ResponseResult.success();
    }
    //查询订单记录（连表查询）
    @GetMapping("/findOrderDetailsByUserId")
    public ResponseResult<List<UserFoodOrderDetailVo>> findOrderDetailsByUserId(
            @RequestParam("userId") Integer userId) {

        List<UserFoodOrderDetailVo> orders = foodService.findOrderDetailsByUserId(userId);

        return ResponseResult.success(orders);
    }
    @PostMapping("/notify")
    public String notify(@RequestParam Map<String, String> params) {
        // 处理支付宝通知
        String out_trade_no = params.get("out_trade_no");

        foodService.updateByUserinfoId(out_trade_no);

        return "success";
    }

}
